#if TWEENSYSTEM_ENABLE_TEXTMESHPRO

using System; 
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace XFGameFramework.TweenSystem
{
    /// <summary>
    /// TextMeshPro动画拓展
    /// </summary>
    public static class TextMeshProExtensions  
    {
        /// <summary>
        /// 渐变文本
        /// </summary>
        /// <param name="text">TextMeshProUGUI对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<float> TweenText(this TextMeshProUGUI text, string target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0,int loopCount = -1)
        {
            text.text = string.Empty;
            Action<TweenerCore<float>> callback = (TweenerCore<float> t) =>
            {
                text.text = target.Substring(0, (int)Mathf.Lerp(0, target.Length, t.Value));
            };

            return TweenManager.ComponentTween(text, 0, 1, duration, loop, ease, curve, ingoreTimeScale, callback, delay,0,loopCount);
        }

        /// <summary>
        /// 渐变文本
        /// </summary>
        /// <param name="text">TextMeshPro对象</param>
        /// <param name="target">目标值</param>
        /// <param name="duration">持续时间</param>
        /// <param name="loop">循环模式</param>
        /// <param name="ease">缓动曲线</param>
        /// <param name="curve">自定义的缓动曲线</param>
        /// <param name="ingoreTimeScale">是否忽略时间缩放</param>
        /// <param name="delay">延迟</param>
        /// <param name="loopCount">循环次数</param>
        /// <returns></returns>
        public static TweenerCore<float> TweenText(this TextMeshPro text, string target, float duration, LoopMode loop = LoopMode.Once, Ease ease = Ease.Linear, AnimationCurve curve = null, bool ingoreTimeScale = false, float delay = 0,int loopCount = -1)
        {
            text.text = string.Empty;
            Action<TweenerCore<float>> callback = (TweenerCore<float> t) =>
            {
                text.text = target.Substring(0, (int)Mathf.Lerp(0, target.Length, t.Value));
            };

            return TweenManager.ComponentTween(text, 0, 1, duration, loop, ease, curve, ingoreTimeScale, callback, delay,0,loopCount);
        }
    }

}



#endif